****This code completes the analyses on the 2020 ANES Time Series Study data for the paper,
****"Affective polarization and Misinformation"
***Libby Jenke
**December 14, 2022
*Results in the paper are generated using Stata 14.2 for Mac

*TO OUTPUT TABLES, RUN SOCMED_REPLICATION.DO FIRST. THEN, WITHOUT CLEARING STATA, RUN THIS CODE. 
*DOING SO PUTS RESULTS FROM BOTH DATASETS TOGETHER IN ONE TABLE.

*cd " "
use ~/Data/timeseriesData_rep.dta

svyset [pweight=V200010B]

*Define control vars
global control = "polatt polknow educ female age black hispan otherrace income urban"
global control2 = "polatt female age black hispan otherrace income urban"

**Table 2: In-group and out-group separately for Dems and Reps together
eststo: svy: reg misinf affpol partyex ideoex $control
	estimates store InParty2
eststo: svy: reg out_misinf affpol partyex ideoex $control
	estimates store OutParty2	
esttab InParty1 OutParty1 InParty2 OutParty2 using Tables/table2.tex, label ///
		stats(N r2) star(* 0.10 ** 0.05 *** 0.01) replace b(%9.2f)	

***Table 3: In-group and out-group separately for Dems
eststo: svy: reg misinf affpol partyex ideoex $control if party<3
	estimates store InPartyDems2
eststo: svy: reg out_misinf affpol  partyex ideoe $control if party<3
	estimates store OutPartyDems2
esttab InPartyDems1 OutPartyDems1 InPartyDems2 OutPartyDems2 using Tables/table3.tex, label ///
	stats(N r2) star(* 0.10 ** 0.05 *** 0.01) b(%9.2f) replace

***Table 4: In-group and out-group separately for Reps
eststo: svy: reg misinf affpol partyex ideoex $control if party>3
	estimates store InPartyRep2
eststo: svy: reg out_misinf affpol  partyex ideoex $control if party>3
	estimates store OutPartyRep2
esttab InPartyRep1 OutPartyRep1 InPartyRep2 OutPartyRep2 using Tables/table4.tex, label ///
	stats(N r2) star(* 0.10 ** 0.05 *** 0.01) b(%9.2f) replace

***Table 5: Interaction with political sophistication
eststo: svy: reg misinf c.affpol##c.polsophis partyex ideoex $control2
	est store InPartySophis2
	margins, at(affpol=(0 1) polsophis=(0 1))
eststo: svy: reg out_misinf c.affpol##c.polsophis partyex ideoex $control2
	est store OutPartySophis2
esttab InPartySophis1 OutPartySophis1 InPartySophis2 OutPartySophis2 using Tables/table5.tex, label ///
	stats(N r2) star(* 0.10 ** 0.05 *** 0.01) b(%9.2f) replace

***Figure 1
coefplot InPartyDems1 InPartyRep1 InPartyDems2 InPartyRep2, xline(0) drop(female hispan otherrace income urban _cons) graphregion(color(white))
	graph save "inParty.pdf", replace
coefplot OutPartyDems1 OutPartyRep1 OutPartyDems2 OutPartyRep2, xline(0) drop(female hispan otherrace income urban _cons) graphregion(color(white))
	graph save "outParty.pdf", replace
